import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getPopupContainer } from '@vben/utils';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    fieldName: 'platform',
    label: '平台标识',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
      options: getDictOptions('sys_plat_type'),
    },
  },
  {
    fieldName: 'aiModel',
    label: 'AI模型',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
      options: getDictOptions('sys_process_category'),
    },
  },
  {
    component: 'Input',
    fieldName: 'name',
    label: '名称',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: 'ID',
    field: 'id',
  },
  {
    title: 'AI模型',
    field: 'aiModel',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
        return renderDict(row.aiModel, 'sys_process_category');
      },
    },
  },
  {
    title: '名称',
    field: 'name',
  },
  {
    title: '提示词',
    field: 'cue',
  },
  {
    title: '角色',
    field: 'role',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
        return renderDict(row.role, 'sys_employee_role');
      },
    },
  },
  {
    title: '角色状态',
    field: 'status',
    formatter: ({ cellValue }) => {
      switch (cellValue) {
        case 1: {
          return '正常';
        }
        default: {
          return '未知';
        }
      }
    },
  },
  {
    title: '显示顺序',
    field: 'sort',
  },
  {
    title: '备注',
    field: 'remark',
  },
  {
    title: '平台标识',
    field: 'platform',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
        return renderDict(row.platform, 'sys_plat_type');
      },
    },
  },

  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const modalSchema: FormSchemaGetter = () => [
  {
    label: 'ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '名称',
    fieldName: 'name',
    component: 'Input',
    rules: 'required',
  },
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'deptId',
  },
  {
    component: 'TreeSelect',
    componentProps: {
      getPopupContainer,
    },
    dependencies: {
      show: (model) => model.parentId !== 0,
      triggerFields: ['parentId'],
    },
    fieldName: 'parentId',
    label: '上级部门',
    rules: 'selectRequired',
  },
  {
    label: '员工职责',
    fieldName: 'cue',
    component: 'Input',
    rules: 'required',
    width: 180,
  },
  {
    label: 'AI模型',
    fieldName: 'aiModel',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
      options: getDictOptions('sys_process_category'),
    },
    rules: 'required',
  },
  {
    label: '角色',
    fieldName: 'role',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
      options: getDictOptions('sys_employee_role'),
    },
    rules: 'required',
  },
  {
    label: '平台标识',
    fieldName: 'platform',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
      options: getDictOptions('sys_plat_type'),
    },
    rules: 'required',
  },
  {
    label: '显示顺序',
    fieldName: 'sort',
    component: 'Input',
    rules: 'required',
  },

  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
    rules: 'required',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
  },
  {
    component: 'TreeSelect',
    componentProps: {
      getPopupContainer,
    },
    dependencies: {
      show: (model) => model.parentId !== 0,
      triggerFields: ['parentId'],
    },
    fieldName: 'categoryId',
    label: '行业分类',
    rules: 'selectRequired',
  },
  {
    label: '角色',
    fieldName: 'role',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
      options: getDictOptions('sys_employee_role'),
    },
    rules: 'required',
  },
  {
    label: 'AI模型',
    fieldName: 'aiModel',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
      options: getDictOptions('sys_process_category'),
    },
    rules: 'required',
  },
  {
    label: '平台标识',
    fieldName: 'platform',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_USER_SEX 便于维护
      options: getDictOptions('sys_plat_type'),
    },
    rules: 'required',
  },
  {
    label: '员工职责',
    fieldName: 'cue',
    component: 'Textarea',
    componentProps: {
      rows: 12,
    },
    rules: 'required',
    width: 180,
  },
  {
    component: 'Textarea',
    fieldName: 'remark',
    formItemClass: 'items-start',
    label: '备注',
  },
];
